package com;
//定义一个Person类{name,age,job},初始化Person对象数组，有3个person对象
//并按照age从大到小进行排序，名字长度按从小到大。提示：使用冒泡排序

public class Exercise01 {
    public static void main(String[] args) {
        Person[] people = new Person[3];
        people[0] = new Person("smith", 26, "javeEE工程师");
        people[1] = new Person("tom", 34, "运维工程师");
        people[2] = new Person("jack", 28, "前端开发工程师");
        for (int i = 0; i < people.length; i++) {
            System.out.println(people[i]);
        }
        for (int i = 0; i < people.length-1; i++) {
            Person temp = null;
            for(int j = 0 ; j < people.length-1-i; j++) {
                if(people[j].getAge()<people[j+1].getAge()){
                    temp = people[j];
                    people[j] = people[j+1];
                    people[j+1] = temp;
                if(people[j].getName().length()>people[j+1].getName().length()){
                    temp = people[j];
                    people[j] = people[j+1];
                    people[j+1] = temp;
                }
                }
            }
        }
        System.out.println("=====排序后的效果=====");
        for (int i = 0; i < people.length; i++) {
            System.out.println(people[i]);
        }
    }
}
    class Person {
        private String name;
        private int age;
        private String job;

        public Person(String name, int age, String job) {
            this.name = name;
            this.age = age;
            this.job = job;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getName() {
            return name;
        }

        public void setAge(int age) {
            this.age = age;
        }

        public int getAge() {
            return age;
        }

        public void setJob(String job) {
            this.job = job;
        }

        public String getJob() {
            return job;
        }

        @Override
        public String toString() {
            return "Person{"+"name='" + name + '\'' + ", age=" + age + ", job='" + job + '\'' + '}';
        }
    }



